//
//  BWFLoginViewController.swift
//  网易新闻项目
//
//  Created by 薄文飞 on 16/3/10.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

let url = "https://api.weibo.com/oauth2/authorize"

let client_id = "3843061997"
let redirect_uri = "http://www.douyutv.com/"

//let redirect_uri = "http://weibo.com/u/2056856190/home?wvr=5/"
class BWFLoginViewController: UIViewController {

    override func loadView() {
        view = webView

        let request = NSURLRequest(URL: requestUrl)
        print(requestUrl)
        webView.loadRequest(request)
        
    }
   
//    document.getElementById('userId').value='709724343@qq.com';document.getElementById('passwd').value='tuichuqq02190104'

    override func viewDidLoad() {
        super.viewDidLoad()
        
        navigationItem.leftBarButtonItem = UIBarButtonItem( titel: "返回", target: self, action: "back")
        navigationItem.rightBarButtonItem = UIBarButtonItem(titel: "自动填充", target: self , action: "autoFill")
        
        navigationItem.title = "新浪微博登录"
    }
    
    func autoFill() {
    
      let jssStr = "document.getElementById('userId').value='709724343@qq.com';document.getElementById('passwd').value='tuichuqq02190104'"
        
        webView.stringByEvaluatingJavaScriptFromString(jssStr)

    }
    
    func back() {
    
        dismissViewControllerAnimated(true, completion: nil)
    }
    
   private lazy var requestUrl  = NSURL(string: "https://api.weibo.com/oauth2/authorize?client_id=\(client_id)&redirect_uri=\(redirect_uri)")!


    lazy var webView : UIWebView = {
    
        let wv = UIWebView()
        wv.backgroundColor = UIColor.blueColor()
        return wv
    }()
}

//https://api.weibo.com/oauth2/authorize?client_id=123050457758183&redirect_uri=http://www.example.com/response&response_type=code
